/*
 *  Copyright (c) 2013 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.cloopen.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
package com.bst.bsj.biz.impl;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.homewaimai.common.lang.StringUtil;

import config.ConfigReader;

public class PropertiesUtil {

	public static final String ACTIVE_SMSAPI = "active_smsapi";

	/**
	 * Demo rest server address info
	 */
	public static String SERVER_ADDRESS = "server_address";

	/**
	 * Demo rest server port info
	 */
	public static String SERVER_PORT = "server_port";

	/**
	 * Demo test main account info
	 */
	public static String Main_Account = "main_account";

	/**
	 * Demo test main token info
	 */
	public static String Main_Token = "main_token";

	/**
	 * Demo test sub account info
	 */
	public static String Sub_Account = "sub_account";

	/**
	 * Demo test sub token info
	 */
	public static String Sub_Token = "sub_token";

	/**
	 * Demo test sub nikename
	 */
	public static String Sub_Name = "";

	/**
	 * Demo test VoIP account
	 */
	public static String VoIP_ID = "voip_account";

	/**
	 * Demo test VoIP password
	 */
	public static String VoIP_PWD = "voip_password";

	/**
	 * Demo test app id
	 */
	public static String App_ID = "app_id";

	/**
	 * sms模版ID
	 */
	public static String Template_ID = "template_id";

	/**
	 * 竞拍模版ID
	 */
	public static String Auction_Template_ID = "auction_template_id";

	/**
	 * 根据key读取value
	 * 
	 * @param filePath
	 *            资源文件路径
	 * @param key
	 *            资源文件中key名称
	 */
	public static String readValue(String filePath, String key) {
		Properties props = new Properties();
		InputStream in = null;
		try {
			in = new BufferedInputStream(new FileInputStream(
					filePath));
			props.load(in);
			String value = props.getProperty(key);
			System.out.println(key + "=" + value);
			return value;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally{
			if(in!=null){
				try {
					in.close();
				} catch (IOException e) {
				}
			}
		}
	}

	/**
	 * 根据key读取value
	 * 
	 * @param filePath
	 *            资源文件路径
	 * @param key
	 *            资源文件中key名称
	 */
	public static String readValue(String key) {
		Properties props = new Properties();
		InputStream in=null;
		try {
			in = ConfigReader.readInputStream("sms.properties");
			props.load(in);
			String value = props.getProperty(key);
			System.out.println(key + "=" + value);
			return value;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally{
			if(in!=null){
				try {
					in.close();
				} catch (IOException e) {
				}
			}
		}
	}
	/**
	 * 根据key读取value
	 * 
	 * @param filePath
	 *            资源文件路径
	 * @param key
	 *            资源文件中key名称
	 */
	public static String readValueWithPrefix(String keyString ,String prefix) {
		String key =null;
		if(StringUtil.isBlank(prefix)){
			key=keyString;
		}else{
			key =prefix+"."+keyString;
		}
		Properties props = new Properties();
		InputStream in=null;
		try {
			in = ConfigReader.readInputStream("sms.properties");
			props.load(in);
			String value = props.getProperty(key);
			//System.out.println(key + "=" + value);
			return value;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}finally{
			if(in!=null){
				try {
					in.close();
				} catch (IOException e) {
				}
			}
		}
	}

	public static void main(String[] args) {

	}
}
